<?php

/**
 * This is the model class for table "identities".
 *
 * The followings are the available columns in table 'identities':
 * @property integer $id
 * @property integer $employeeId
 * @property string $name
 * @property string $code
 * @property string $status
 * @property string $expiredDate
 * @property string $note
 */
class Identity extends ActiveRecordUser {

	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Identity the static model class
	 */
	public static function model($className = __CLASS__) {
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName() {
		return 'identities';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('employeeId, name', 'required'),
			array('employeeId', 'numerical', 'integerOnly'=>true),
			array('name, code', 'length', 'max'=>128),
			array('status', 'length', 'max'=>64),
			array(
				'expiredDate',
				'date',
				'format'=>'yyyy-MM-dd',
			),
			array('note', 'safe'),
			array(
				'employeeId, name, code, status, expiredDate, note',
				'safe',
				'on'=>'search'
			),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations() {
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'employee'=>array(self::BELONGS_TO, 'Employee', 'employeeId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels() {
		return array(
			'id'=>'ID',
			'employeeId'=>'Employee',
			'name'=>'Name',
			'code'=>'Code',
			'status'=>'Status',
			'expiredDate'=>'Expired Date',
			'note'=>'Note',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search() {
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria = new CDbCriteria;

		$criteria->compare('id', $this->id);
		$criteria->compare('employeeId', $this->employeeId);
		$criteria->compare('name', $this->name, true);
		$criteria->compare('code', $this->code, true);
		$criteria->compare('status', $this->status, true);
		$criteria->compare('expiredDate', $this->expiredDate, true);
		$criteria->compare('note', $this->note, true);

		return new CActiveDataProvider($this, array(
				'criteria'=>$criteria,
			));
	}

	public function behaviors() {
		return array(
			'nameBehavior'=>array(
				'class'=>'application.behaviors.IdentityListBehavior',
				'attribute'=>'name',
			),
		);
	}

}